/**
 * This file is part of 1genia trampoline
 * Copyright (C) 2007 1genia (contact@1genia.com)
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; version 3 of the License. 
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; see the file COPYING.TXT.  If not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA. 
 **/
package com.genia.toolbox.web.taglib.common;

import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.tagext.TagSupport;

/**
 * Tag that handles the body. It will just find the HtmlTag that must enclose it
 * and pass to it the value of its {@link javax.servlet.jsp.tagext.BodyContent}.
 */
@SuppressWarnings("serial")
public class BodyTag
    extends BodyTagSupport
{
  /**
   * the css class name of the body.
   */
  private String styleClass;



  /**
   * Process the end tag for this instance. This method is invoked by the JSP
   * page implementation object on all Tag handlers.
   * <p>
   * This method will be called after returning from doStartTag. The body of the
   * action may or may not have been evaluated, depending on the return value of
   * doStartTag.
   * <p>
   * If this method returns EVAL_PAGE, the rest of the page continues to be
   * evaluated. If this method returns SKIP_PAGE, the rest of the page is not
   * evaluated, the request is completed, and the doEndTag() methods of
   * enclosing tags are not invoked. If this request was forwarded or included
   * from another page (or Servlet), only the current page evaluation is
   * stopped.
   * <p>
   * The JSP container will resynchronize the values of any AT_BEGIN and AT_END
   * variables (defined by the associated TagExtraInfo or TLD) after the
   * invocation of doEndTag().
   * 
   * @return indication of whether to continue evaluating the JSP page.
   * @see javax.servlet.jsp.tagext.Tag#doEndTag()
   */
  @Override
  public int doEndTag()
  {
    ((HtmlPageAggregator) TagSupport.findAncestorWithClass(this, HtmlPageAggregator.class)).doAfterBodyTag(this);
    return EVAL_PAGE;
  }



  /**
   * getter for the styleClass property.
   * 
   * @return the styleClass
   */
  public String getStyleClass()
  {
    return styleClass;
  }



  /**
   * Called on a Tag handler to release state. The page compiler guarantees that
   * JSP page implementation objects will invoke this method on all tag
   * handlers, but there may be multiple invocations on doStartTag and doEndTag
   * in between.
   * 
   * @see javax.servlet.jsp.tagext.BodyTagSupport#release()
   */
  @Override
  public void release()
  {
    super.release();
    styleClass = null;
  }



  /**
   * setter for the styleClass property.
   * 
   * @param styleClass
   *          the styleClass to set
   */
  public void setStyleClass(String styleClass)
  {
    this.styleClass = styleClass;
  }
}
